package com.sm.auth.controller;

import com.sm.auth.dto.LoginDto;
import com.sm.auth.service.AuthService;
import com.sm.common.constants.HttpStatus;
import com.sm.common.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("auth")
@Slf4j
public class AuthController {
    @Autowired
    private  AuthService authService;
    @Autowired
    private  PasswordEncoder passwordEncoder;


    @PostMapping("sys")
    public Result login(@RequestBody LoginDto loginDto){
        log.info("username:{},password:{}",loginDto.getUsername(),loginDto.getPassword());
        String token = authService.login(loginDto);
        return new Result(HttpStatus.SUCCESS,"登录成功!!!", token);
    }
    @GetMapping("test")
    @PreAuthorize("hasAnyAuthority('system:user:list')")
    public Result test() {
        String passwordSecret = passwordEncoder.encode("123456");
        System.out.println(passwordSecret);
        return Result.success().put("data",passwordSecret);
    }
}
